package com.doge.calcalbum.analysis

import com.doge.calcalbum.api.ObserverAdapter
import com.doge.calcalbum.api.api
import com.doge.calcalbum.api.subscribeOnIO
import com.doge.calcalbum.utils.appContext
import com.doge.calcalbum.utils.runOnIO
import com.tendcloud.tenddata.TCAgent

fun analysisEvent(eventId: String) = runOnIO {
    TCAgent.onEvent(appContext, eventId)
    uploadEvent(eventId)
}

fun asyncAnalysisEvent(block:()->String) = runOnIO {
    analysisEvent(block())
}

private fun uploadEvent(eventId: String) {
    api
        .uploadEvent(eventId)
        .subscribeOnIO()
        .subscribe(object : ObserverAdapter<Any>() {
            override fun onError(e: Throwable) = Unit
        })
}